var mainDiv = document.getElementById("maindiv");
var startdiv = document.getElementById("startdiv");
var scorediv = document.getElementById("scorediv");
var scorelabel = document.getElementById("label");
var suspenddiv = document.getElementById("suspenddiv");
var enddiv1 = document.getElementById("enddiv1");
var enddiv2 = document.getElementById("enddiv2");
var planscore = document.getElementById("planscore");
var infodiv = document.getElementById("infodiv");
var timediv = document.getElementById("timediv");
var Boom = document.getElementById("Boom");
var waring = document.getElementById("waring");
var boomdiv = document.getElementById("boomdiv");
var powerdiv = document.getElementById("powerdiv");
var win = document.getElementById("windiv");
var black = document.getElementById("black");
var scores = 0;
var sec = 0;
var timer = 0;
var alpha = 10.0;
var waringAlp = 1.0;
var isAlpha = true;
var boomNum = 2;
var power = 1.0;
var isBoss = false;
var isBoss2 = false;
var showboss = 30;
var stage2time = 20;
var showboss2;
var isleft = true;
var isAni1 = false;
var isAni2 = false;
var isAni3 = false;
var isWaring = false;
var isStage2 = false;
var isjiguang = false;
/*
 创建飞机类
 */
function plan(hp,X,Y,sizeX,sizeY,score,dietime,sudu,boomimage,imagesrc){
    this.planX=X;
    this.planY=Y;
    this.imagenode=null;
    this.planhp=hp;
    this.planscore=score;
    this.plansizeX=sizeX;
    this.plansizeY=sizeY;
    this.planboomimage=boomimage;
    this.planisdie=false;
    this.plandietimes=0;
    this.plandietime=dietime;
    this.plansudu=sudu;
//行为
/*
移动行为
     */
    this.planmove=function(){
		if(!isBoss&&!isBoss2)
		{
			if(scores<=200){
				this.imagenode.style.top=this.imagenode.offsetTop+this.plansudu+"px";
			}
			else if(scores>200&&scores<=500){
				this.imagenode.style.top=this.imagenode.offsetTop+this.plansudu+1+"px";
			}
			else if(scores>500&&scores<=800){
				this.imagenode.style.top=this.imagenode.offsetTop+this.plansudu+2+"px";
			}
			else if(scores>800&&scores<=1200){
				this.imagenode.style.top=this.imagenode.offsetTop+this.plansudu+3+"px";
			}
			else if(scores>1200&&scores<=2000){
				this.imagenode.style.top=this.imagenode.offsetTop+this.plansudu+4+"px";
			}
			else if(scores>2000){
				this.imagenode.style.top=this.imagenode.offsetTop+this.plansudu+5+"px";
			}
		}
		else 
		if(isBoss&&!isBoss2)
		{
			if(this.imagenode.offsetTop<30)
			{
				this.imagenode.style.top=this.imagenode.offsetTop+this.plansudu+"px";
			}
			else if(this.imagenode.offsetTop>=30)
			{
				if(this.imagenode.offsetLeft<10)
				{
					isleft = true;
				}
				if(isleft)
				{
				this.imagenode.style.left=this.imagenode.offsetLeft+1+"px";
				}
				else
				{
					this.imagenode.style.left=this.imagenode.offsetLeft-1+"px";
				}
				if(this.imagenode.offsetLeft>100)
				{
					isleft = false;
				}
			}
		}
		else
		if(isBoss2)
		{
			if(this.imagenode.offsetTop<2)
			{
				this.imagenode.style.top=this.imagenode.offsetTop+this.plansudu+"px";
			}
		}
    }
    this.init=function(){
        this.imagenode=document.createElement("img");
        this.imagenode.style.left=this.planX+"px";
        this.imagenode.style.top=this.planY+"px";
        this.imagenode.src=imagesrc;
        mainDiv.appendChild(this.imagenode);
    }
    this.init();
}

//创建拾取boom
function eatB(X,Y,sizeX,sizeY,imagesrc){
	this.eatBX = X;
	this.eatBY = Y;
	this.eatBimage=null;
    this.eatBsizeX=sizeX;
    this.eatBsizeY=sizeY;
	
	this.eatBmove=function(){
        this.eatBimage.style.top=this.eatBimage.offsetTop+1+"px";
    }
    this.init=function(){
        this.eatBimage=document.createElement("img");
        this.eatBimage.style.left= this.eatBX+"px";
        this.eatBimage.style.top= this.eatBY+"px";
        this.eatBimage.src=imagesrc;
        mainDiv.appendChild(this.eatBimage);
    }
    this.init();
}

function oddeatB(X,Y){
    eatB.call(this,X,Y,20,20,"image/boompic.png");
}

//创建拾取power
function eatP(X,Y,sizeX,sizeY,imagesrc){
	this.eatPX = X;
	this.eatPY = Y;
	this.eatPimage=null;
    this.eatPsizeX=sizeX;
    this.eatPsizeY=sizeY;
	
	this.eatPmove=function(){
        this.eatPimage.style.top=this.eatPimage.offsetTop+1+"px";
    }
    this.init=function(){
        this.eatPimage=document.createElement("img");
        this.eatPimage.style.left= this.eatPX+"px";
        this.eatPimage.style.top= this.eatPY+"px";
        this.eatPimage.src=imagesrc;
        mainDiv.appendChild(this.eatPimage);
    }
    this.init();
}

function oddeatP(X,Y){
    eatP.call(this,X,Y,20,20,"image/Power.png");
}

/*创建子弹类*/
function bullet(X,Y,sizeX,sizeY,imagesrc){
    this.bulletX=X;
    this.bulletY=Y;
    this.bulletimage=null;
    this.bulletattach=1;
    this.bulletsizeX=sizeX;
    this.bulletsizeY=sizeY;
	//行为
	/*移动行为*/
    this.bulletmove=function(){
        this.bulletimage.style.top=this.bulletimage.offsetTop-20+"px";
    }
    this.init=function(){
        this.bulletimage=document.createElement("img");
        this.bulletimage.style.left= this.bulletX+"px";
        this.bulletimage.style.top= this.bulletY+"px";
        this.bulletimage.src=imagesrc;
        mainDiv.appendChild(this.bulletimage);
    }
    this.init();
}
/*创建单行子弹类*/
function oddbullet(X,Y){
    bullet.call(this,X,Y,6,14,"image/bullet1.png");
}
/////////////////////////////////////////////////////////////
/*创建boss弹幕类*/
function shoot(X,Y,sizeX,sizeY,imagesrc){
    this.shootX=X;
    this.shootY=Y;
    this.shootimage=null;
    this.shootattach=1;
    this.shootsizeX=sizeX;
    this.shootsizeY=sizeY;
	//行为
	/*移动行为*/
    this.shootmove=function(){
        this.shootimage.style.top=this.shootimage.offsetTop+5+"px";
    }
    this.init=function(){
        this.shootimage=document.createElement("img");
        this.shootimage.style.left= this.shootX+"px";
        this.shootimage.style.top= this.shootY+"px";
        this.shootimage.src=imagesrc;
        mainDiv.appendChild(this.shootimage);
    }
    this.init();
}
/*创建单行boss弹幕类*/
function oddshoot(X,Y){
    shoot.call(this,X,Y,40,40,"image/bossShoot.png");
}
/*创建boss弹幕类1*/
function shoot1(X,Y,sizeX,sizeY,imagesrc){
    this.shoot1X=X;
    this.shoot1Y=Y;
    this.shoot1image=null;
    this.shoot1attach=1;
    this.shoot1sizeX=sizeX;
    this.shoot1sizeY=sizeY;
	//行为
	/*移动行为*/
    this.shoot1move=function(){
        this.shoot1image.style.top=this.shoot1image.offsetTop+2+"px";
    }
    this.init=function(){
        this.shoot1image=document.createElement("img");
        this.shoot1image.style.left= this.shoot1X+"px";
        this.shoot1image.style.top= this.shoot1Y+"px";
        this.shoot1image.src=imagesrc;
        mainDiv.appendChild(this.shoot1image);
    }
    this.init();
}
function oddshoot1(X,Y){
    shoot1.call(this,X,Y,40,40,"image/bossShoot1.png");
}
/*创建单行boss弹幕类2*/
function shoot2(X,Y,sizeX,sizeY,imagesrc){
    this.shoot2X=X;
    this.shoot2Y=Y;
    this.shoot2image=null;
    this.shoot2attach=1;
    this.shoot2sizeX=sizeX;
    this.shoot2sizeY=sizeY;
	//行为
	/*移动行为*/
    this.shoot2move=function(){
        this.shoot2image.style.top=this.shoot2image.offsetTop+2+"px";
		this.shoot2image.style.left=this.shoot2image.offsetLeft-1+"px";
    }
    this.init=function(){
        this.shoot2image=document.createElement("img");
        this.shoot2image.style.left= this.shoot2X+"px";
        this.shoot2image.style.top= this.shoot2Y+"px";
        this.shoot2image.src=imagesrc;
        mainDiv.appendChild(this.shoot2image);
    }
    this.init();
}
/*创建单行boss弹幕类2*/
function oddshoot2(X,Y){
    shoot2.call(this,X,Y,40,40,"image/bossShoot1.png");
}
/*创建单行boss弹幕类3*/
function shoot3(X,Y,sizeX,sizeY,imagesrc){
    this.shoot3X=X;
    this.shoot3Y=Y;
    this.shoot3image=null;
    this.shoot3attach=1;
    this.shoot3sizeX=sizeX;
    this.shoot3sizeY=sizeY;
	//行为
	/*移动行为*/
    this.shoot3move=function(){
        this.shoot3image.style.top=this.shoot3image.offsetTop+2+"px";
		this.shoot3image.style.left=this.shoot3image.offsetLeft+1+"px";
    }
    this.init=function(){
        this.shoot3image=document.createElement("img");
        this.shoot3image.style.left= this.shoot3X+"px";
        this.shoot3image.style.top= this.shoot3Y+"px";
        this.shoot3image.src=imagesrc;
        mainDiv.appendChild(this.shoot3image);
    }
    this.init();
}
/*创建单行boss弹幕类3*/
function oddshoot3(X,Y){
    shoot3.call(this,X,Y,40,40,"image/bossShoot1.png");
}
/*创建bossEX弹幕类*/
function shootEx(X,Y,sizeX,sizeY,imagesrc){
    this.shootExX=X;
    this.shootExY=Y;
    this.shootEximage=null;
    this.shootExattach=1;
    this.shootExsizeX=sizeX;
    this.shootExsizeY=sizeY;
	var pos = random(100,510);
	var mod = random(2,4);
	//行为
	/*移动行为*/
    this.shootExmove=function(){
		if(this.shootEximage.offsetTop>=pos)
		{
			if(mod == 1)
			{
				this.shootEximage.style.top=this.shootEximage.offsetTop+2+"px";
			}
			else if(mod == 2)
			{
				this.shootEximage.style.top=this.shootEximage.offsetTop+2+"px";
				this.shootEximage.style.left=this.shootEximage.offsetLeft+2+"px";
				this.shootEximage.style.transform = "rotate(-45deg)";
			}
			else if(mod == 3)
			{
				this.shootEximage.style.top=this.shootEximage.offsetTop+2+"px";
				this.shootEximage.style.left=this.shootEximage.offsetLeft-2+"px";
				this.shootEximage.style.transform = "rotate(45deg)";
				
			}
		}
		else
		{
			this.shootEximage.style.top=this.shootEximage.offsetTop+2+"px";
		}
    }
    this.init=function(){
        this.shootEximage=document.createElement("img");
        this.shootEximage.style.left= this.shootExX+"px";
        this.shootEximage.style.top= this.shootExY+"px";
        this.shootEximage.src=imagesrc;
        mainDiv.appendChild(this.shootEximage);
    }
    this.init();
}
/*创建单行boss弹幕类*/
function oddshootEx(X,Y){
    shootEx.call(this,X,Y,18,40,"image/fire.png");
}
//////////////////////////////////////////////////////////////////

/*
创建敌机类
 */
function enemy(hp,a,b,sizeX,sizeY,score,dietime,sudu,boomimage,imagesrc){
    plan.call(this,hp,random(a,b),-100,sizeX,sizeY,score,dietime,sudu,boomimage,imagesrc);
}
//产生min到max之间的随机数
function random(min,max){
    return Math.floor(min+Math.random()*(max-min));
}

/*
创建本方飞机类
 */
function ourplan(X,Y){
    var imagesrc="image/我的飞机.gif";
    plan.call(this,1,X,Y,55,90,0,660,0,"image/本方飞机爆炸.gif",imagesrc);
    this.imagenode.setAttribute('id','ourplan');
}
/*
创建本方飞机
*/
var selfplan = new ourplan(120,485);
//移动事件
var ourPlan = document.getElementById('ourplan');
var yidong = function(){
	var oevnet = window.event||arguments[0];
	var selfplanX = oevnet.clientX;
	var selfplanY = oevnet.clientY;
	ourPlan.style.left = selfplanX-selfplan.plansizeX/2+"px";
	ourPlan.style.top = selfplanY-selfplan.plansizeY/2+"px";
}
var yidongmobile = function()
{
	if(event.touches.length === 1)
	{
		event.preventDefault();
		var selfplanX = event.touches[0].pageX;
		var selfplanY = event.touches[0].pageY;
		ourPlan.style.left = selfplanX-selfplan.plansizeX/2+"px";
		ourPlan.style.top = selfplanY-selfplan.plansizeY/2+"px";
	}
}
/*
暂停事件
*/
var number = 0;
var zanting = function(){
	infodiv.style.display = "none";
	if(number == 0)
	{
		suspenddiv.style.display = "block";
		if(document.removeEventListener){
			mainDiv.removeEventListener("mousemove",yidong,true);
			bodyobj.removeEventListener("mousemove",bianjie,true);
		}
		else if(document.detachEvent){
			mainDiv.detachEvent("onmousemove",yidong);
			bodyobj.detachEvent("onmousemove",bianjie);
		}
		clearInterval(set);
		number = 1;
	}
	else{
		suspenddiv.style.display = "none";
		if(document.addEventListener){
			mainDiv.addEventListener("mousemove",yidong,true);
			bodyobj.addEventListener("mousemove",bianjie,true);
			
		}
		else if(document.attachEvent){
			mainDiv.attachEvent("onmousemove",yidong);
			bodyobj.attachEvent("onmousemove",bianjie);
		}
		set = setInterval(start,20);
		number = 0;
	}
}
//判断本方飞机是否移出边界，如果移出边界，则取消mousemove事件，反之加上mousemove事件
var bianjie = function(){
	var oevnet = window.event||arguments[0];
	var bodyobjX = oevnet.clientX;
	var bodyobjY = oevnet.clientY;
	if(bodyobjX<5||bodyobjX>315||bodyobjY<0||bodyobjY>568)
	{
		if(document.removeEventListener)
		{
			mainDiv.removeEventListener("mousemove",yidong,true);
		}
		else if(document.detachEvent)
		{
			mainDiv.detachEvent("onmousemove",yidong);
		}
	}
	else
	{
		if(document.addEventListener)
		{
			mainDiv.addEventListener("mousemove",yidong,true);
		}
		else if(document.attachEvent)
		{
			mainDiv.attachEvent("onmousemove",yidong);
		}
	}
}
var bodyobj = document.getElementsByTagName("body")[0];
document.onkeydown=function(event)
{
	var e = event || window.event || arguments.callee.caller.arguments[0];
	if(e && e.keyCode==27)
	{ // 按 Esc 
		zanting();
    }
}
if(document.addEventListener)
{
	//为本方危机添加移动和暂停
	mainDiv.addEventListener("mousemove",yidong,true);
	//为本方飞机添加boom
	selfplan.imagenode.addEventListener("click",setBoom,true);
	//为body添加判断本方飞机移出边界事件
	bodyobj.addEventListener("mousemove",bianjie,true);
	//为body添加判断本方飞机移出边界事件
	suspenddiv.getElementsByTagName("button")[0].addEventListener("click",zanting,true);
	suspenddiv.getElementsByTagName("button")[1].addEventListener("click",youxishuoming,true);
	//为暂停界面的返回主页按钮添加事件
	suspenddiv.getElementsByTagName("button")[2].addEventListener("click",jixu,true);
}
else if(document.attachEvent)
{
	//为本方飞机添加移动
	mainDiv.attachEvent("onmousemove",yidong);
	//为本方飞机添加boom
	selfplan.imagenode.attachEvent("onclick",setBoom);
	//为body添加判断本方飞机移出边界事件
	bodyobj.attachEvent("onmousemove",bianjie);
	//为暂停界面的继续按钮添加暂停事件
	suspenddiv.getElementsByTagName("button")[0].attachEvent("click",zanting);
	suspenddiv.getElementsByTagName("button")[1].attachEvent("click",youxishuoming,true);
	//为暂停界面的返回主页按钮添加事件
	suspenddiv.getElementsByTagName("button")[2].attachEvent("click",jixu,true);
}
//初始化隐藏本方飞机
selfplan.imagenode.style.display = "none";
/*
敌机对象组
*/
var enemys = [];
/*
子弹对象组
*/
var bullets = [];
var shoots = [];
var shoots1 = [];
var shoots2 = [];
var shoots3 = [];
var shootExs = [];
var eatBs = [];
var eatPs = [];
var mark = 0;
var mark1 = 0;
var backgroundPositionY = 0;
function start()
{
	boomdiv.innerHTML = "B" + ":"+ boomNum;	
	if(power>=3.0)
	{
		power = 3.0;
	}
	powerdiv.innerHTML = "P" + ":"+ power.toFixed(1);
	mainDiv.style.backgroundPositionY = backgroundPositionY + "px";
	backgroundPositionY += 0.5;
	if(backgroundPositionY == 568){
		backgroundPositionY = 0;
	}
	mark++;
	var enemyslen = enemys.length;
	//创建boss
	if(sec == showboss&&!isBoss)
	{
		boomNum = 0;
		enemys.push(new enemy(100,25,100,208,97,99999,800,1,"image/bossex.gif","image/boss.png"));
		isBoss = true;
	}
	if(sec == showboss2&&!isBoss)
	{
		boomNum = 0;
		enemys.push(new enemy(100,0,1,120,115,59999,800,1,"image/本方飞机爆炸.gif","image/boss2.png"));
		enemys.push(new enemy(100,199,200,120,115,59999,800,1,"image/本方飞机爆炸.gif","image/boss2.png"));
		isBoss = true;
		isBoss2 = true;
	}
	/*创建敌方飞机*/
	if(!isBoss&&sec<=showboss-5)
	{
		if(mark == 30)
		{
			mark1++;
			//中飞机
			if(mark1%5 == 0)
			{
				enemys.push(new enemy(10,25,274,69,56,50,360,random(1,3),"image/中飞机爆炸.gif",
					"image/enemy3_fly_1.png"));
			}
			//大飞机
			if(mark1%15 == 0)
			{
				enemys.push(new enemy(24,57,210,100,104,100,1620,1,"image/大飞机爆炸.gif",
					"image/enemy2_fly_1.png"));
			}
			//小飞机
			else
			{
				enemys.push(new enemy(1,19,286,44,41,10,360,random(1,4),"image/小飞机爆炸.gif",
					"image/enemy1_fly_1.png"));
			}
			mark = 0;
		}
	}
	if(isStage2)
	{
		if(!isBoss2&&sec<=showboss2-5)
		{
			if(mark == 30)
			{
				mark1++;
				//中飞机
				if(mark1%5 == 0)
				{
					enemys.push(new enemy(10,25,274,69,56,50,360,random(1,3),"image/中飞机爆炸.gif",
						"image/enemy3_fly_1.png"));
				}
				//大飞机
				if(mark1%15 == 0)
				{
					enemys.push(new enemy(24,57,210,100,104,100,1620,1,"image/大飞机爆炸.gif",
						"image/enemy2_fly_1.png"));
				}
				//小飞机
				else
				{
					enemys.push(new enemy(1,19,286,44,41,10,360,random(1,4),"image/小飞机爆炸.gif",
						"image/enemy1_fly_1.png"));
				}
				mark = 0;
			}
		}
	}
	/*敌方飞机*/

	for(var i = 0;i<enemyslen;i++)
	{
		if(enemys[i].planisdie != true)
		{
			enemys[i].planmove();
		}
		if(enemys[i].imagenode.offsetTop>100)
		{
			
		}
		/*
		如果敌机超出边界，删除敌机
		*/
		if(enemys[i].imagenode.offsetTop>568){
			mainDiv.removeChild(enemys[i].imagenode);
			enemys.splice(i,1);
			enemyslen--;
		}
		//当敌机死亡标记为true时，经过一段事件后清除敌机
		if(enemys[i].planisdie == true)
		{
			enemys[i].plandietimes += 20;
			if(enemys[i].plandietimes == enemys[i].plandietime)
			{
				mainDiv.removeChild(enemys[i].imagenode);
				enemys.splice(i,1);
				enemyslen--;
			}
		}
		if(isBoss&&!isBoss2)
		{
			//创建弹幕
			if(mark%100 == 0)
			{
				shoots.push(new oddshoot(parseInt(enemys[i].imagenode.style.left)+84,
				parseInt(enemys[i].imagenode.style.top)+40));
				
				shoots1.push(new oddshoot1(parseInt(enemys[i].imagenode.style.left)+35,
				parseInt(enemys[i].imagenode.style.top)+60));
				shoots2.push(new oddshoot2(parseInt(enemys[i].imagenode.style.left)+35,
				parseInt(enemys[i].imagenode.style.top)+60));
				shoots3.push(new oddshoot3(parseInt(enemys[i].imagenode.style.left)+35,
				parseInt(enemys[i].imagenode.style.top)+60));
				
				shoots1.push(new oddshoot1(parseInt(enemys[i].imagenode.style.left)+173,
				parseInt(enemys[i].imagenode.style.top)+60));
				shoots2.push(new oddshoot2(parseInt(enemys[i].imagenode.style.left)+173,
				parseInt(enemys[i].imagenode.style.top)+60));
				shoots3.push(new oddshoot3(parseInt(enemys[i].imagenode.style.left)+173,
				parseInt(enemys[i].imagenode.style.top)+60));
			}
		}
		if(isBoss2)
		{
			if(mark%40 == 0)
			{
				shootExs.push(new oddshootEx(parseInt(enemys[i].imagenode.style.left)+50,
				parseInt(enemys[i].imagenode.style.top)+85));
			}
		}
	}
	/*
	创建子弹
	*/
	if(mark%5 == 0)
	{
		if(power<2.0)
		{
			//单行
			bullets.push(new oddbullet(parseInt(selfplan.imagenode.style.left)+26,
			parseInt(selfplan.imagenode.style.top)+5));
		}
		else if(power >=2.0&&power<3.0)
		{
			//两行
			bullets.push(new oddbullet(parseInt(selfplan.imagenode.style.left)+18,
			parseInt(selfplan.imagenode.style.top)+25));
			bullets.push(new oddbullet(parseInt(selfplan.imagenode.style.left)+32,
			parseInt(selfplan.imagenode.style.top)+25));
		}
		else if(power >=3.0&&power<4.0)
		{
			//三行
			bullets.push(new oddbullet(parseInt(selfplan.imagenode.style.left)+26,
			parseInt(selfplan.imagenode.style.top)+5));
			bullets.push(new oddbullet(parseInt(selfplan.imagenode.style.left)+14,
			parseInt(selfplan.imagenode.style.top)+28));
			bullets.push(new oddbullet(parseInt(selfplan.imagenode.style.left)+38,
			parseInt(selfplan.imagenode.style.top)+28));
		}
	}
	/*
	移动子弹
	*/
	var bulletslen = bullets.length;
	for(var i = 0;i<bulletslen;i++)
	{
		bullets[i].bulletmove();
		/*
		如果子弹超出边界，删除子弹
		*/
		if(bullets[i].bulletimage.offsetTop<0)
		{
			mainDiv.removeChild(bullets[i].bulletimage);
			bullets.splice(i,1);
			bulletslen--;
		}
	}
	///////////////////////////////////////////////////
	/*移动boss弹幕*/
	var shootslen = shoots.length;
	for(var i = 0;i<shootslen;i++)
	{
		shoots[i].shootmove();
		/*
		如果子弹超出边界，删除弹幕
		*/
		if(shoots[i].shootimage.offsetTop<0||shoots[i].shootimage.offsetTop>568)
		{
			mainDiv.removeChild(shoots[i].shootimage);
			shoots.splice(i,1);
			shootslen--;
		}
	}
	
	var shoots1len = shoots1.length;
	for(var i = 0;i<shoots1len;i++)
	{
		shoots1[i].shoot1move();
		/*
		如果子弹超出边界，删除弹幕
		*/
		if(shoots1[i].shoot1image.offsetTop<0||shoots1[i].shoot1image.offsetTop>568)
		{
			mainDiv.removeChild(shoots1[i].shoot1image);
			shoots1.splice(i,1);
			shoots1len--;
		}
	}
	
	var shoots2len = shoots2.length;
	for(var i = 0;i<shoots2len;i++)
	{
		shoots2[i].shoot2move();
		/*
		如果子弹超出边界，删除弹幕
		*/
		if(shoots2[i].shoot2image.offsetTop<0||shoots2[i].shoot2image.offsetTop>568||
		   shoots2[i].shoot2image.offsetLeft<0||shoots2[i].shoot2image.offsetLeft>300)
		{
			mainDiv.removeChild(shoots2[i].shoot2image);
			shoots2.splice(i,1);
			shoots2len--;
		}
	}
	
	var shoots3len = shoots3.length;
	for(var i = 0;i<shoots3len;i++)
	{
		shoots3[i].shoot3move();
		/*
		如果子弹超出边界，删除弹幕
		*/
		if(shoots3[i].shoot3image.offsetTop<0||shoots3[i].shoot3image.offsetTop>568||
		   shoots3[i].shoot3image.offsetLeft<0||shoots3[i].shoot3image.offsetLeft>300)
		{
			mainDiv.removeChild(shoots3[i].shoot3image);
			shoots3.splice(i,1);
			shoots3len--;
		}
	}
	
	var shootExslen = shootExs.length;
	for(var i = 0;i<shootExslen;i++)
	{
		shootExs[i].shootExmove();
		/*
		如果子弹超出边界，删除弹幕
		*/
		if(shootExs[i].shootEximage.offsetTop<0||shootExs[i].shootEximage.offsetTop>568||
		   shootExs[i].shootEximage.offsetLeft<0||shootExs[i].shootEximage.offsetLeft>300)
		{
			mainDiv.removeChild(shootExs[i].shootEximage);
			shootExs.splice(i,1);
			shootExslen--;
		}
	}
	
	//移动boom道具
	var eatBslen = eatBs.length;
	for(var i = 0;i<eatBslen;i++)
	{
		eatBs[i].eatBmove();
		/*
		如果Boom道具超出边界，删除子弹
		*/
		if(eatBs[i].eatBimage.offsetTop<0||eatBs[i].eatBimage.offsetTop>568)
		{
			mainDiv.removeChild(eatBs[i].eatBimage);
			eatBs.splice(i,1);
			eatBslen--;
		}
	}
	
	//移动power道具
	var eatPslen = eatPs.length;
	for(var i = 0;i<eatPslen;i++)
	{
		eatPs[i].eatPmove();
		/*
		如果Boom道具超出边界，删除子弹
		*/
		if(eatPs[i].eatPimage.offsetTop<0||eatPs[i].eatPimage.offsetTop>568)
		{
			mainDiv.removeChild(eatPs[i].eatPimage);
			eatPs.splice(i,1);
			eatPslen--;
		}
	}
	///////////////////////////////////////////////

	/*
	碰撞判断
	*/
    for(var k=0;k<bulletslen;k++)
	{
        for(var j=0;j<enemyslen;j++)
		{
            //判断碰撞本方飞机
            if(enemys[j].planisdie==false)
			{
                if(enemys[j].imagenode.offsetLeft+enemys[j].plansizeX>=selfplan.imagenode.offsetLeft&&
				enemys[j].imagenode.offsetLeft<=selfplan.imagenode.offsetLeft+selfplan.plansizeX)
				{
                  if(enemys[j].imagenode.offsetTop+enemys[j].plansizeY>=selfplan.imagenode.offsetTop+40&&
				  enemys[j].imagenode.offsetTop<=selfplan.imagenode.offsetTop-20+selfplan.plansizeY)
				  {
                    selfplanEX();
                  }
                }
                //判断子弹与敌机碰撞
                if((bullets[k].bulletimage.offsetLeft+bullets[k].bulletsizeX>enemys[j].imagenode.offsetLeft)
					&&(bullets[k].bulletimage.offsetLeft<enemys[j].imagenode.offsetLeft+enemys[j].plansizeX))
				{
                    if(bullets[k].bulletimage.offsetTop<=enemys[j].imagenode.offsetTop+enemys[j].plansizeY
					&&bullets[k].bulletimage.offsetTop+bullets[k].bulletsizeY>=enemys[j].imagenode.offsetTop)
					{
                        //敌机血量减子弹攻击力
                        enemys[j].planhp=enemys[j].planhp-bullets[k].bulletattach;
                        //敌机血量为0，敌机图片换为爆炸图片，死亡标记为true，计分
                        if(enemys[j].planhp==0)
						{
                            scores=scores+enemys[j].planscore;
                            scorelabel.innerHTML=scores;
                            enemys[j].imagenode.src=enemys[j].planboomimage;
                            enemys[j].planisdie=true;
							var r = random(1,10)
							if(r == 9)
							{
							eatBs.push(new oddeatB(parseInt(enemys[j].imagenode.style.left)+17,
							parseInt(enemys[j].imagenode.style.top)+25));
							}
							else if(r<=5)
							{
								eatPs.push(new oddeatP(parseInt(enemys[j].imagenode.style.left)+17,
								parseInt(enemys[j].imagenode.style.top)+25));
							}
                        }
                        //删除子弹
                        mainDiv.removeChild(bullets[k].bulletimage);
						bullets.splice(k,1);
						bulletslen--;
						break;	
                    }
                }
            }
        }
		//如果得分大于999999则切换到stage2
		if(scores>=99999&&!isBoss2)
		{
			scores = scores - 99999;
			scorelabel.innerHTML=scores;
			black.style.display = "block";
			stage1anim();
			isStage2 = true;
			isBoss = false;
			mark = 0;
			showboss2 = sec + stage2time;
			isAni1 = false;
			isAni2 = false;
			isAni3 = false;
			isWaring = false;
		}
		if(isBoss2&&scores >= 99999)
		{
			setTimeout(complete,1000);
		}
		
    }
	//吃boom
	for(var n = 0;n<eatBslen;n++)
	{
		if(eatBs[n].eatBimage.offsetLeft+eatBs[n].eatBsizeX>=selfplan.imagenode.offsetLeft&&
		eatBs[n].eatBimage.offsetLeft<=selfplan.imagenode.offsetLeft+selfplan.plansizeX)
		{
		  if(eatBs[n].eatBimage.offsetTop+eatBs[n].eatBsizeY>=selfplan.imagenode.offsetTop+40&&
		  eatBs[n].eatBimage.offsetTop<=selfplan.imagenode.offsetTop-20+selfplan.plansizeY)
		  {
			//boom数+1；消除boom对象
			mainDiv.removeChild(eatBs[n].eatBimage);
			eatBs.splice(n,1);
			eatBslen--;
			boomNum++;
		  }
		}
	}
	//吃power
	for(var n = 0;n<eatPslen;n++)
	{
		if(eatPs[n].eatPimage.offsetLeft+eatPs[n].eatPsizeX>=selfplan.imagenode.offsetLeft&&
		eatPs[n].eatPimage.offsetLeft<=selfplan.imagenode.offsetLeft+selfplan.plansizeX)
		{
		  if(eatPs[n].eatPimage.offsetTop+eatPs[n].eatPsizeY>=selfplan.imagenode.offsetTop+40&&
		  eatPs[n].eatPimage.offsetTop<=selfplan.imagenode.offsetTop-20+selfplan.plansizeY)
		  {
			//power+0.1；消除power对象
			mainDiv.removeChild(eatPs[n].eatPimage);
			eatPs.splice(n,1);
			eatPslen--;
			power = power + 0.1;
		  }
		}
	}
	//boss弹幕与本方飞机碰撞
	for(var n = 0;n<shootslen;n++)
	{
		if(shoots[n].shootimage.offsetLeft+shoots[n].shootsizeX>=selfplan.imagenode.offsetLeft&&
		shoots[n].shootimage.offsetLeft<=selfplan.imagenode.offsetLeft+selfplan.plansizeX)
		{
			if(shoots[n].shootimage.offsetTop+shoots[n].shootsizeY>=selfplan.imagenode.offsetTop+40&&
			shoots[n].shootimage.offsetTop+80<=selfplan.imagenode.offsetTop-20+selfplan.plansizeY)
			{
				selfplanEX();
			}
		}
	}
	//boss弹幕1与本方飞机碰撞
	for(var n = 0;n<shoots1len;n++)
	{
		if(shoots1[n].shoot1image.offsetLeft+shoots1[n].shoot1sizeX>=selfplan.imagenode.offsetLeft&&
		shoots1[n].shoot1image.offsetLeft<=selfplan.imagenode.offsetLeft+selfplan.plansizeX)
		{
			if(shoots1[n].shoot1image.offsetTop+shoots1[n].shoot1sizeY>=selfplan.imagenode.offsetTop+40&&
			shoots1[n].shoot1image.offsetTop<=selfplan.imagenode.offsetTop-20+selfplan.plansizeY)
			{
				selfplanEX();
			}
		}
	}
	//boss弹幕2与本方飞机碰撞
	for(var n = 0;n<shoots2len;n++)
	{
		if(shoots2[n].shoot2image.offsetLeft+shoots2[n].shoot2sizeX>=selfplan.imagenode.offsetLeft&&
		shoots2[n].shoot2image.offsetLeft<=selfplan.imagenode.offsetLeft+selfplan.plansizeX)
		{
			if(shoots2[n].shoot2image.offsetTop+shoots2[n].shoot2sizeY>=selfplan.imagenode.offsetTop+40&&
			shoots2[n].shoot2image.offsetTop<=selfplan.imagenode.offsetTop-20+selfplan.plansizeY)
			{
				selfplanEX();
			}
		}
	}
	//boss弹幕3与本方飞机碰撞
	for(var n = 0;n<shoots3len;n++)
	{
		if(shoots3[n].shoot3image.offsetLeft+shoots3[n].shoot3sizeX>=selfplan.imagenode.offsetLeft&&
		shoots3[n].shoot3image.offsetLeft<=selfplan.imagenode.offsetLeft+selfplan.plansizeX)
		{
			if(shoots3[n].shoot3image.offsetTop+shoots3[n].shoot3sizeY>=selfplan.imagenode.offsetTop+40&&
			shoots3[n].shoot3image.offsetTop<=selfplan.imagenode.offsetTop-20+selfplan.plansizeY)
			{
				selfplanEX();
			}
		}
	}
	for(var n = 0;n<shootExslen;n++)
	{
		if(shootExs[n].shootEximage.offsetLeft+shootExs[n].shootExsizeX>=selfplan.imagenode.offsetLeft&&
		shootExs[n].shootEximage.offsetLeft<=selfplan.imagenode.offsetLeft+selfplan.plansizeX)
		{
			if(shootExs[n].shootEximage.offsetTop+shootExs[n].shootExsizeY>=selfplan.imagenode.offsetTop+20&&
			shootExs[n].shootEximage.offsetTop<=selfplan.imagenode.offsetTop-10+selfplan.plansizeY)
			{
				selfplanEX();
			}
		}
	}
	
	timer++
	if(timer == 50)
	{
		sec++;
		timediv.innerHTML = "时间" + ":"+sec;
		timer = 0;
	}
	if(alpha == 10.0)
	{
		Boom.style.display = "none";
	}
	//三次waring动画
	if(sec == showboss-2&&!isAni1)
	{
		waring.style.display = "block";
		waringAnim();
		isAni1 = true;
	}
	if(sec == showboss-1&&!isAni2)
	{
		isWaring = false;
		waring.style.display = "block";
		waringAnim();
		isAni2 = true;
	}
	if(sec == showboss&&!isAni3)
	{
		isWaring = false;
		waring.style.display = "block";
		waringAnim();
		isAni3 = true;
	}
	//stage2三次waring动画
	if(sec == showboss2-2&&!isAni1)
	{
		waring.style.display = "block";
		waringAnim();
		isAni1 = true;
	}
	if(sec == showboss2-1&&!isAni2)
	{
		isWaring = false;
		waring.style.display = "block";
		waringAnim();
		isAni2 = true;
	}
	if(sec == showboss2&&!isAni3)
	{
		isWaring = false;
		waring.style.display = "block";
		waringAnim();
		isAni3 = true;
	}
	
}
function selfplanEX()
{
	//碰撞本方飞机，游戏结束，统计分数
	selfplan.imagenode.src="image/本方飞机爆炸.gif";
	enddiv1.style.display="block";
	planscore.innerHTML=scores;
	if(document.removeEventListener)
	{
		mainDiv.removeEventListener("mousemove",yidong,true);
		bodyobj.removeEventListener("mousemove",bianjie,true);
	}
	else if(document.detachEvent)
	{
		mainDiv.detachEvent("onmousemove",yidong);
		bodyobj.removeEventListener("mousemove",bianjie,true);
	}
	clearInterval(set);
}
function complete()
{
	boomdiv.style.display = "block";
	powerdiv.style.display = "block";
	selfplan.imagenode.style.display = "block";
	scorediv.style.display = "block";
	timediv.style.display = "block";
	mainDiv.style.display = "none";
	win.style.display="block";
	planscore.innerHTML=scores;
	if(document.removeEventListener)
	{
		mainDiv.removeEventListener("mousemove",yidong,true);
		bodyobj.removeEventListener("mousemove",bianjie,true);
	}
	else if(document.detachEvent)
	{
		mainDiv.detachEvent("onmousemove",yidong);
		bodyobj.removeEventListener("mousemove",bianjie,true);
	}
	clearInterval(set);
}
var set;
function begin()
{
	boomdiv.style.display = "block";
	powerdiv.style.display = "block";
	startdiv.style.display = "none";
	mainDiv.style.display = "block";
	selfplan.imagenode.style.display = "block";
	scorediv.style.display = "block";
	timediv.style.display = "block";
	/*
	调用开始函数
	*/
	
	set = setInterval(start,20);
}
//设置Boom
function setBoom()
{
	if(boomNum > 0 )
	{
		boomNum--;
		Boom.style.display = "block";
		alphaAnim();
		isBoom = true;
		for(var j = 0;j<enemys.length;j++)
		{
		enemys[j].imagenode.src=enemys[j].planboomimage;
		enemys[j].planisdie=true;
		}
	}
}
//Boom的渐隐动画
function alphaAnim()
{
	Boom.style.opacity = alpha/10.0;
	alpha = alpha - 1.0;
	var ID = setTimeout(alphaAnim,100);
	if(alpha <= 0)
	{
		clearTimeout(ID);
		alpha = 10.0;
		Boom.style.display = "none";
	}
}
//waring的渐隐动画
function waringAnim()
{
	waring.style.opacity = waringAlp/10.0;
	if(!isWaring)
	{
		waringAlp = waringAlp + 1.0;
	}
	if(waringAlp >= 9.0)
	{
		isWaring = true;
	}
	if(isWaring)
	{
		waringAlp = waringAlp - 1.0;
	}
	var ID = setTimeout(waringAnim,50);
	if(waringAlp < 1.0)
	{
		clearTimeout(ID);
		waring.style.display = "none";
	}
}
//stage1背景的渐隐动画
var stage1alpha = 0.0;
var isStage1 = false;
function stage1anim()
{
	black.style.opacity = stage1alpha/10.0;
	if(!isStage1)
	{
		stage1alpha = stage1alpha + 1.0;
	}
	if(stage1alpha >= 10.0)
	{
		//只能使用绝对路径，原因不明
		mainDiv.style.backgroundImage = "url(image/background_3.png)";
		isStage1 = true;
	}
	if(isStage1)
	{
		stage1alpha = stage1alpha - 1.0;
	}
	var ID = setTimeout(stage1anim,100);
	if(stage1alpha < 1.0)
	{
		clearTimeout(ID);
		black.style.display = "none";
	}
}

//暂停界面游戏说明事件
function youxishuoming()
{
	infodiv.style.display = "block";
}
//暂停界面继续事件
function jixu()
{
	location.reload(true);
	infodiv.style.display = "none";
}